home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / clients / ffindcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-09  |  4.1 KB  |  125 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *      This product includes software developed by the University of
  16.  *      California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34.     /*********************************************************************\
  35.     *  Copyright (c) 1993 by Michael Meskes                               *
  36.     *  (meskes@ulysses.informatik.rwth-aachen.de)                         *
  37.     *                                                                     *
  38.     *  You may copy or modify this file in any manner you wish, provided  *
  39.     *  that this notice is always included, and that you hold the author  *
  40.     *  harmless for any loss or damage resulting from the installation or *
  41.     *  use of this software.                                              *
  42.     \*********************************************************************/
  43.  
  44. #include "tweak.h"
  45. #include "client_def.h"
  46. #include "c_extern.h"
  47. #include "bsd_extern.h"
  48. #include <stdio.h>
  49. #ifndef VMS
  50. #include <sys/types.h>
  51. /* #include <time.h> */
  52. #include <fcntl.h>
  53. #else
  54. #include "types.h"
  55. #include "time.h"
  56. #endif
  57. #ifdef HAVE_UNISTD_H
  58. #include <unistd.h>
  59. #endif
  60. #include "find.h"
  61.  
  62. extern PLAN *plan;
  63.  
  64. time_t now;            /* time find was run */
  65. int isoutput;            /* user specified output operator */
  66. int process;            /* process current directory */
  67.  
  68. static void usage_ffind();
  69.  
  70. static void eval_file PROTO4(char *, name, struct stat *, sbufp,
  71.                  int,  mode, int,  level)
  72. {
  73.   register PLAN *p;
  74.   
  75.   for (p = plan; p && (p->eval)(p, sbufp, name); p = p->next);
  76. }
  77.  
  78. static int eval_dir PROTO3(char *, name, struct stat *, sbufp, u_long, sum)
  79. {
  80.   register PLAN *p;
  81.   
  82.   process = 0;
  83.   for (p = plan; p && (p->eval)(p, sbufp, name); p = p->next);
  84.   return (process);
  85. }
  86.  
  87. int main PROTO3(int, argc, char **,  argv, char **, envp)
  88. {
  89.   register char **p;
  90.   char *singlefile[2], **files;
  91.   
  92.   env_client();
  93.   (void)time(&now);    /* initialize the time-of-day */
  94.   
  95.   p = ++argv;
  96.   
  97.   /* First option delimits the file list. */
  98.   while (*p && !option(*p)) p++;
  99.   if (p == argv) usage_ffind();
  100.   
  101.   find_formplan(p);
  102.   
  103.   /* Execute plan for all file lists */
  104.   while (*argv) {
  105.     if (argv >= p) break;
  106.     if (!(files = glob(*argv))) {
  107.       files = singlefile;
  108.       singlefile[0] = *argv;
  109.       singlefile[1] = 0;
  110.     }
  111.     for ( ; *files; files++)
  112.       util_process_file(*files, 0, eval_file, eval_dir, 0L, 0);
  113.       
  114.     argv++;
  115.   }
  116.   
  117.   client_done();
  118. }
  119.  
  120. static void usage_ffind PROTO0((void))
  121. {
  122.   fprintf(stderr,"usage: ffind file [file ...] expression\n");
  123.   exit(1);
  124. }
  125.